home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Complete Linux
/
Complete Linux.iso
/
xwindows
/
demos
/
xfract_1.z
/
xfract_1
/
xfractint-1.06
/
general.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-09-28
|
19KB
|
928 lines
/* generalasm.c
* This file contains routines to replace general.asm.
*
* This file Copyright 1991 Ken Shirriff. It may be used according to the
* fractint license conditions, blah blah blah.
*/
#include <string.h>
#ifndef NOBSTRING
/* If this gives you an error, read the README and modify the Makefile. */
#include <bstring.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/time.h>
#include "fractint.h"
int overflow = 0;
char boxx[9216], boxy[4096];
char boxvalues[2048];
char tstack[4096];
extern int tabmode;
int DivideOverflow = 0;
int iit=0;
int cpu=0; /* cpu type: 86, 186, 286, or 386 */
#ifndef XFRACT
int fpu=0; /* fpu type: 0, 87, 287, 387 */
#else
int fpu=1;
#endif
char *extraseg=0; /* extra 64K segment (allocated by init) */
/* ********************** Mouse Support Variables ************************** */
int lookatmouse=0; /* see notes at mouseread routine */
int savebase=0; /* base clock ticks */
int saveticks=0; /* save after this many ticks */
int finishrow=0; /* save when this row is finished */
int inside_help = 0;
extern int slides; /* 1 for playback */
void toextra(tooffset, fromaddr, fromcount)
int tooffset;
char *fromaddr;
int fromcount;
{
bcopy(fromaddr,(char *)(extraseg+tooffset),fromcount);
}
void fromextra(fromoffset, toaddr, tocount)
int fromoffset;
char *toaddr;
int tocount;
{
bcopy((char *)(extraseg+fromoffset),toaddr,tocount);
}
int
cmpextra(cmpoffset,cmpaddr,cmpcount)
int cmpoffset;
char *cmpaddr;
int cmpcount;
{
return bcmp((char *)(extraseg+cmpoffset),cmpaddr,cmpcount);
}
/*
; ****************** Function initasmvars() *****************************
*/
void
initasmvars()
{
if (cpu!=0) return;
overflow = 0;
extraseg = malloc(0x18000);
/* set cpu type */
cpu = 1;
/* set fpu type */
#ifndef XFRACT
fpu = 0;
#else
fpu = 1;
#endif
}
void fpe_handler(int signum)
{
overflow = 1;
}
/*
;
; 32-bit integer multiply routine with an 'n'-bit shift.
; Overflow condition returns 0x7fffh with overflow = 1;
;
; long x, y, z, multiply();
; int n;
;
; z = multiply(x,y,n)
;
*/
static float
tofloat(x,n)
long x;
int n;
{
return (float)x/(float)(1<<n);
}
/*
* 32 bit integer multiply with n bit shift.
* Note that we fake integer multiplication with floating point
* multiplication.
*/
long
multiply(x, y, n)
long x,y;
int n;
{
register long l;
l = ((float)x)* ((float)y)/(float)(1<<n);
if (l==0x7fffffff) {
overflow = 1;
}
return l;
}
/*
;
; 32-bit integer divide routine with an 'n'-bit shift.
; Overflow condition returns 0x7fffh with overflow = 1;
;
; z = divide(x,y,n); z = x / y;
*/
long
divide(x,y,n)
long x,y;
int n;
{
return (long) ( ((float)x)/ ((float)y)*(float)(1<<n));
}
/*
; ****************** Function getakey() *****************************
; **************** Function keypressed() ****************************
; 'getakey()' gets a key from either a "normal" or an enhanced
; keyboard. Returns either the vanilla ASCII code for regular
; keys, or 1000+(the scan code) for special keys (like F1, etc)
; Use of this routine permits the Control-Up/Down arrow keys on
; enhanced keyboards.
;
; The concept for this routine was "borrowed" from the MSKermit
; SCANCHEK utility
;
; 'keypressed()' returns a zero if no keypress is outstanding,
; and the value that 'getakey()' will return if one is. Note
; that you must still call 'getakey()' to flush the character.
; As a sidebar function, calls 'help()' if appropriate, or
; 'tab_display()' if appropriate.
; Think of 'keypressed()' as a super-'kbhit()'.
*/
int keybuffer = 0;
keypressed() {
int ch;
ch = getkeynowait();
if (!ch) return 0;
keybuffer = ch;
if (ch==F1 && helpmode) {
keybuffer = 0;
inside_help = 1;
help(0);
inside_help = 0;
restore_active_ovly();
return 0;
} else if (ch==TAB && tabmode) {
keybuffer = 0;
tab_display();
restore_active_ovly();
return 0;
}
return ch;
}
/* Wait for a key.
* This should be used instead of:
* while (!keypressed()) {}
* If timeout=1, waitkeypressed will time out after .5 sec.
*/
waitkeypressed(timeout)
int timeout;
{
int status;
while (!keybuffer) {
keybuffer = getkeyint(1);
if (timeout) break;
}
return keypressed();
}
/*
* This routine returns a key, ignoring F1
*/
getakeynohelp() {
int ch;
while (1) {
ch = getakey();
if (ch != F1) break;
}
return ch;
}
/*
* This routine returns a keypress
*/
getakey()
{
int ch;
do {
ch = getkeyint(1);
} while (ch==0);
return ch;
}
/*
* This routine returns the current key, or 0.
*/
getkeynowait() {
return getkeyint(0);
}
/*
* This is the low level key handling routine.
* If block is set, we want to block before returning, since we are waiting
* for a key press.
* We also have to handle the slide file, etc.
*/
getkeyint(block)
int block;
{
int ch;
int curkey;
if (keybuffer) {
ch = keybuffer;
keybuffer = 0;
return ch;
}
curkey = xgetkey(0);
if (slides==1 && curkey == ESC) {
stopslideshow();
return 0;
}
if (curkey==0 && slides==1) {
curkey = slideshw();
}
if (curkey==0 && block) {
curkey = xgetkey(1);
if (slides==1 && curkey == ESC) {
stopslideshow();
return 0;
}
}
if (curkey && slides==2) {
recordshw(curkey);
}
return curkey;
}
/*
; ****************** Function buzzer(int buzzertype) *******************
;
; Sound a tone based on the value of the parameter
;
; 0 = normal completion of task
; 1 = interrupted task
; 2 = error contition
; "buzzer()" codes: strings of two-word pairs
; (frequency in cycles/sec, delay in milliseconds)
; frequency == 0 means no sound
; delay == 0 means end-of-tune
*/
void
buzzer(buzzertype)
int buzzertype;
{
printf("\007");
fflush(stdout);
if (buzzertype==0) {
redrawscreen();
}
}
/*
; ***************** Function delay(int delaytime) ************************
;
; performs a delay loop for 'delaytime' milliseconds
*/
void
delay(delaytime)
int delaytime;
{
static struct timeval delay;
delay.tv_sec = delaytime/1000;
delay.tv_usec = (delaytime%1000)*1000;
(void) select(0, (int *) 0, (int *) 0, (int *) 0, &delay);
}
/*
; ************** Function tone(int frequency,int delaytime) **************
;
; buzzes the speaker with this frequency for this amount of time
*/
void
tone(frequency, delaytime)
int frequency, delaytime;
{
}
/*
; ************** Function snd(int hertz) and nosnd() **************
;
; turn the speaker on with this frequency (snd) or off (nosnd)
;
; *****************************************************************
*/
void
snd(hertz)
int hertz;
{
}
void
nosnd()
{}
/*
; long readticker() returns current bios ticker value
*/
long
readticker()
{
return clock_ticks();
}
/*
; ************************* Far Segment RAM Support **************************
;
;
; farptr = (char far *)farmemalloc(long bytestoalloc);
; (void)farmemfree(farptr);
*/
VOIDPTR
farmemalloc(len)
long len;
{
return (VOIDPTR )malloc((unsigned)len);
}
void
farmemfree(addr)
VOIDPTR addr;
{
free((char *)addr);
}
erasesegment(segaddress,segvalue)
{
}
int
farread(handle, buf, len)
int handle;
VOIDPTR buf;
unsigned len;
{
return read(handle, buf, len);
}
int
farwrite(handle, buf, len)
int handle;
VOIDPTR buf;
unsigned len;
{
return write(handle,buf,len);
}
long
normalize(ptr)
char *ptr;
{
return (long) ptr;
}
/*
; *************** Far string/memory functions *********
*/
int
far_strlen (a)
char *a;
{
return strlen(a);
}
int
far_strcpy (a,b)
char *a,*b;
{
return (int)strcpy(a,b);
}
int
far_strcmp (a,b)
char *a, *b;
{
return strcmp(a,b);
}
int
far_stricmp(a,b)
char *a,*b;
{
return stricmp(a,b);
}
int
far_strnicmp(a,b,n)
char *a,*b;
int n;
{
return strnicmp(a,b,n);
}
int
far_strcat (a,b)
char *a,*b;
{
return (int)strcat(a,b);
}
int
far_memset ( a,c,len)
VOIDPTR a;
int c